package com.top75;

/**
 * @Author: huangzhigao
 * @Date: 2023/5/10 20:09
 */
public class Code1137 {
    public int tribonacci(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1 || n == 2) {
            return 1;
        }
        int pre1 = 0;
        int pre2 = 1;
        int pre3 = 2;
        int res = 0;
        for (int i = 3; i <= n; i++) {
            res = pre1 + pre2 + pre3;
            pre1 = pre2;
            pre2 = pre3;
            pre3 = res;
        }
        return res;
    }
}
